﻿//code by Heskey0
//https://space.bilibili.com/455965619
//https://github.com/Heskey0

using System;
using Teresa;
using UnityEngine;

namespace Common.DesignPattern
{
    public class Singleton<T> where T : class, new()
    {
        private static T _instance = null;
        private static object LockObj = new object();
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (LockObj)
                    {
                        if (_instance==null)
                        {
                            _instance = new T();
                        }
                    }
                }
                return _instance;
            }
        }
    }

    public class MonoSingleton<T> : MonoBehaviour where T : Component
    {
        private static T _instance;

        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    MonoSingletonMgr.Instance.AddMonoSingleton<T>();
                }

                return _instance;
            }
        }
        
        
    }
}
